package com.zhuyp.spring.boot.utils;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.URL;
import java.net.URLDecoder;
import java.net.UnknownHostException;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.support.RequestContext;

import net.sf.json.JSONObject;

public class Common {
	
    // 默认除法运算精度
    private static final int DEF_DIV_SCALE = 10;

    /***
     * 判断是否存在于数组
     * 
     * @param arr
     * @param targetValue
     * @return
     */
    public static boolean isExistInArray(Object[] arr, Object... targetValue) {
        for (Object obj : arr) {
            for (Object tar : targetValue) {
                if (obj.equals(tar)) {
                    return true;
                }
            }
        }
        return false;
    }

    /***
     * 判断该字符串是否是数字
     * 
     * @author chanvincent
     * @date 2015年11月12日 下午3:05:59
     * @param str
     * @return
     */
    public static boolean isNumeric(String str) {
        Pattern pattern = Pattern.compile("[0-9]*");
        return pattern.matcher(str).matches();
    }

    /**
     * 
     * 判断该字符串是否是小数
     * 
     * @author 何信
     * @date 2016年8月16日 下午3:42:14
     * @param str
     * @return
     */
    public static boolean isNumericDecimal(String str) {
        if (isEmpty(str)) {
            return false;
        }
        Pattern pattern = Pattern.compile("[0-9]*.[0-9]*");
        return pattern.matcher(str).matches();
    }

    /**
     * String转换double
     * 
     * @param string
     * @return double
     */
    public static double convertSourData(String dataStr) throws Exception {
        if (dataStr != null && !"".equals(dataStr)) {
            return Double.valueOf(dataStr);
        }
        throw new NumberFormatException("convert error!");
    }

    /**
     * 判断变量是否为空
     * 
     * @param s
     * @return
     */
    public static boolean isEmpty(String s) {
        if (null == s || "".equals(s) || "".equals(s.trim()) || "null".equalsIgnoreCase(s)) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean isEmpty(Integer s) {
        if (null == s || s == 0) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 使用率计算
     * 
     * @return
     */
    public static String fromUsage(long free, long total) {
        Double d =
                new BigDecimal(free * 100 / total).setScale(1, BigDecimal.ROUND_HALF_UP)
                        .doubleValue();
        return String.valueOf(d);
    }

    /**
     * 返回当前时间 格式：yyyy-MM-dd hh:mm:ss
     * 
     * @return String
     */
    public static String fromDateH() {
        DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        return format1.format(new Date());
    }

    /**
     * 返回当前时间 格式：yyyy-MM-dd
     * 
     * @return String
     */
    public static String fromDateY() {
        DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
        return format1.format(new Date());
    }

    /**
     * 用来去掉List中空值和相同项的。
     * 
     * @param list
     * @return
     */
    public static List<String> removeSameItem(List<String> list) {
        List<String> difList = new ArrayList<String>();
        for (String t : list) {
            if (t != null && !difList.contains(t)) {
                difList.add(t);
            }
        }
        return difList;
    }

    /**
     * 
     * 返回服务器域名
     * 
     * @author hexin-pc
     * @date 2015年8月11日 下午3:49:36
     * @param
     * @return
     */
    public static String getRealm() {
        InetAddress addr;
        try {
            addr = InetAddress.getLocalHost();
            return addr.getCanonicalHostName();
        } catch (UnknownHostException e) {
            return null;
        }

    }

    /**
     * 返回用户的IP地址
     * 
     * @param request
     * @return
     */
    public static String getIpAddr(HttpServletRequest request) {
        String ip = request.getHeader("X-Forwarded-For");
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("WL-Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("HTTP_CLIENT_IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("HTTP_X_FORWARDED_FOR");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getRemoteAddr();
        }
        return ip;
    }

    /**
     * 传入原图名称，，获得一个以时间格式的新名称
     * 
     * @param fileName 原图名称
     * @return
     */
    public static String generateFileName(String fileName) {
        DateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
        String formatDate = format.format(new Date());
        int random = 100000 + new Random().nextInt(99999);
        int position = fileName.lastIndexOf(".");
        String extension = fileName.substring(position).toLowerCase();
        // String orgname = fileName.substring(0,position);
        return formatDate + '-' + random + extension;
    }

    /**
     * 获取文件名,去掉后缀
     * 
     * @param fileName
     * @return
     * @exception @since 1.0.0
     */
    public static String getFileNameWithoutExt(String fileName) {
        int position = fileName.lastIndexOf(".");
        return fileName.substring(0, position);
    }

    /**
     * 获取文件的扩展名
     * 
     * @param fileName
     * @return
     * @exception @since 1.0.0
     */
    public static String getFileExt(String fileName) {
        int position = fileName.lastIndexOf(".");
        return fileName.substring(position);
    }

    /**
     * 取得html网页内容 UTF8编码
     * 
     * @param urlStr 网络地址
     * @return String
     */
    public static String getInputHtmlUTF8(String urlStr) {
        URL url = null;
        try {
            url = new URL(urlStr);
            HttpURLConnection httpsURLConnection = (HttpURLConnection) url.openConnection();

            httpsURLConnection.setRequestMethod("GET");
            httpsURLConnection.setConnectTimeout(5 * 1000);
            httpsURLConnection.connect();
            if (httpsURLConnection.getResponseCode() == 200) {
                // 通过输入流获取网络图片
                InputStream inputStream = httpsURLConnection.getInputStream();
                String data = readHtml(inputStream, "UTF-8");
                inputStream.close();
                return data;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

        return null;

    }

    @SuppressWarnings("resource")
    public static String readNativeFile(String myurl) throws IOException {
        BufferedReader in = null;
        in = new BufferedReader(new FileReader(myurl));
        StringBuffer buffer = new StringBuffer();
        String line = " ";
        while ((line = in.readLine()) != null) {
            buffer.append(line);
        }
        return buffer.toString();
    }

    /**
     * 取得html网页内容 GBK编码
     * 
     * @param urlStr 网络地址
     * @return String
     */
    public static String getInputHtmlGBK(String urlStr) {
        URL url = null;
        try {
            url = new URL(urlStr);
            HttpURLConnection httpsURLConnection = (HttpURLConnection) url.openConnection();

            httpsURLConnection.setRequestMethod("GET");
            httpsURLConnection.setConnectTimeout(5 * 1000);
            httpsURLConnection.connect();
            if (httpsURLConnection.getResponseCode() == 200) {
                // 通过输入流获取网络图片
                InputStream inputStream = httpsURLConnection.getInputStream();
                String data = readHtml(inputStream, "GBK");
                inputStream.close();
                return data;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

        return null;

    }

    /**
     * @param inputStream
     * @param uncode 编码 GBK 或 UTF-8
     * @return
     * @throws Exception
     */
    public static String readHtml(InputStream inputStream, String uncode) throws Exception {
        InputStreamReader input = new InputStreamReader(inputStream, uncode);
        BufferedReader bufReader = new BufferedReader(input);
        String line = "";
        StringBuilder contentBuf = new StringBuilder();
        while ((line = bufReader.readLine()) != null) {
            contentBuf.append(line);
        }
        return contentBuf.toString();
    }

    /**
     * 
     * @return 返回资源的二进制数据 @
     */
    public static byte[] readInputStream(InputStream inputStream) {

        // 定义一个输出流向内存输出数据
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        // 定义一个缓冲区
        byte[] buffer = new byte[1024];
        // 读取数据长度
        int len = 0;
        // 当取得完数据后会返回一个-1
        try {
            while ((len = inputStream.read(buffer)) != -1) {
                // 把缓冲区的数据 写到输出流里面
                byteArrayOutputStream.write(buffer, 0, len);
            }
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        } finally {
            try {
                byteArrayOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }
        }

        // 得到数据后返回
        return byteArrayOutputStream.toByteArray();

    }

    /**
     * 修改配置
     * 
     * @param request
     * @param nodeId
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("/modifySer")
    public static Map<String, Object> modifySer(String key, String value) throws Exception {
        Map<String, Object> dataMap = new HashMap<String, Object>();
        try {
            PropertiesUtils.modifyProperties(key, value);
        } catch (Exception e) {
            dataMap.put("flag", false);
        }
        dataMap.put("flag", true);
        return dataMap;
    }

    /**
     * 获取当前认证通过的用户名
     * 
     * @return
     
    public static String findAuthenticatedUsername() {
        String username = null;
        try {
            Object principal =
                    SecurityContextHolder.getContext().getAuthentication().getPrincipal();
            if (principal instanceof UserDetails) {
                username = ((UserDetails) principal).getUsername();
            } else {
                username = principal.toString();
            }
        } catch (Exception ex) {
            return null;
        }
        return username;
    }*/

    /**
     * 获取登录账号的ID
     * 
     * @author Vincent Email：planegame@qq.com date：2014-2-27
     * @param request
     * @return
     */
    public static String findUserSessionId(HttpServletRequest request) {
        Object ob = request.getSession().getAttribute("userSessionId");
        return ob == null ? null : ob.toString();
    }

    /**
     * 获取登录账号的的对象
     * 
     * @author Vincent Email：planegame@qq.com date：2014-2-27
     * @param request
     * @return Object 返回是Object..需要转型为(Account)Object
     */
    public static Object findUserSession(HttpServletRequest request) {
        return (Object) request.getSession().getAttribute("userSession");
    }

    /**
     * 提供精确的减法运算。
     * 
     * @param v1 被减数
     * @param v2 减数
     * @return 两个参数的差
     */
    public static double sub(double v1, double v2) {
        BigDecimal b1 = new BigDecimal(Double.toString(v1));
        BigDecimal b2 = new BigDecimal(Double.toString(v2));
        return b1.subtract(b2).doubleValue();
    }

    /**
     * 提供精确的加法运算。
     * 
     * @param v1 被加数
     * @param v2 加数
     * @return 两个参数的和
     */
    public static double add(double v1, double v2) {
        BigDecimal b1 = new BigDecimal(Double.toString(v1));
        BigDecimal b2 = new BigDecimal(Double.toString(v2));
        return b1.add(b2).doubleValue();
    }

    public static BigDecimal plus(double v1, double v2, double v3) {
        BigDecimal b1 = new BigDecimal(Double.toString(v1));
        BigDecimal b2 = new BigDecimal(Double.toString(v2));
        BigDecimal b3 = new BigDecimal(Double.toString(v3));
        return b1.add(b2).add(b3);
    }

    /**
     * 提供精确的乘法运算。
     * 
     * @param v1 被乘数
     * @param v2 乘数
     * @return 两个参数的积
     */
    public static double mul(double v1, double v2) {
        if (v1 == 0 || v2 == 0) {
            return 0;
        }
        BigDecimal b1 = new BigDecimal(Double.toString(v1));
        BigDecimal b2 = new BigDecimal(Double.toString(v2));
        return b1.multiply(b2).doubleValue();
    }

    /***
     * 四舍五入 保留4位小数
     * 
     * @param dou
     * @return
     */
    public static double scale(double dou) {
        BigDecimal bg = new BigDecimal(dou);
        double f1 = bg.setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
        return f1;
    }

    /***
     * 四舍五入 保留指定位小数
     * 
     * @param dou
     * @param num
     * @return
     */
    public static double scale(double dou, int num) {
        BigDecimal bg = new BigDecimal(dou);
        double f1 = bg.setScale(num, BigDecimal.ROUND_HALF_UP).doubleValue();
        return f1;
    }

    /**
     * 提供（相对）精确的除法运算，当发生除不尽的情况时，精确到 小数点以后10位，以后的数字四舍五入。
     * 
     * @param v1 被除数
     * @param v2 除数
     * @return 两个参数的商
     */
    public static double div(double v1, double v2) {
        return div(v1, v2, DEF_DIV_SCALE);
    }

    /**
     * 提供（相对）精确的除法运算。当发生除不尽的情况时，由scale参数指 定精度，以后的数字四舍五入。
     * 
     * @param v1 被除数
     * @param v2 除数
     * @param scale 表示表示需要精确到小数点以后几位。
     * @return 两个参数的商
     */
    public static double div(double v1, double v2, int scale) {
        if (scale < 0) {
            throw new IllegalArgumentException("The scale must be a positive integer or zero");
        }
        BigDecimal b1 = new BigDecimal(Double.toString(v1));
        BigDecimal b2 = new BigDecimal(Double.toString(v2));
        return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).doubleValue();
    }

    public static int randomInt() {
        return new Random().nextInt();
    }

    /**
     * 
     * 字符串的截取 去掉 标签
     * <p>
     * <img alt="smiley" height="23" src=
     * "http://localhost/jimu-web/ckeditor/plugins/smiley/images/ue40a.png" title="smiley" width=
     * "23" />大 <img alt="" height="23" src=
     * "http://localhost/jimu-web/ckeditor/plugins/smiley/images/ue412.png" title="" width="23" />大
     * <img alt="broken heart" height="23" src=
     * "http://localhost/jimu-web/ckeditor/plugins/smiley/images/ue404.png" title= "broken heart"
     * width="23" />
     * </p>
     * 😄大😄大\n
     * 
     * @author hexin-pc
     * @date 2015年8月27日 下午10:02:02
     * @param str
     * @return
     */
    public static String cutOutString(String str) {
        str =
                str.replaceAll("<p>", "").replaceAll("</p>", "").replaceAll("&nbsp;", " ")
                        .replaceAll("\n", "").replaceAll("\t", "");
        String regex = "images/0x(.{4,5}).png";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(str);
        while (matcher.find()) {
            str =
                    str.replaceAll(matcher.group(1), String.valueOf(Character.toChars(Integer
                            .valueOf(matcher.group(1), 16))));
        }
        String regex1 = "<img(.{50,110})images/0x";
        Pattern pattern1 = Pattern.compile(regex1);
        Matcher matcher1 = pattern1.matcher(str);
        while (matcher1.find()) {
            str =
                    str.replaceAll(matcher1.group(1), "").replaceAll("<img", "")
                            .replaceAll("images/0x", "");
        }
        String regex2 = ".png(.{15,50})/>";
        Pattern pattern2 = Pattern.compile(regex2);
        Matcher matcher2 = pattern2.matcher(str);
        while (matcher2.find()) {
            str = str.replaceAll(matcher2.group(1), "").replaceAll(".png", "").replaceAll("/>", "");
        }
        return str;

    }

    /**
     * 计算地球上任意两点(经纬度)距离
     * 
     * @param long1 第一点经度
     * @param lat1 第一点纬度
     * @param long2 第二点经度
     * @param lat2 第二点纬度
     * @return 返回距离 单位：米
     */
    public static Double Distance(Double long1, Double lat1, Double long2, Double lat2) {
        if (long1 != null && lat1 != null && long2 != null && lat2 != null) {
            double R = 6378137; // 地球半径
            lat1 = lat1 * Math.PI / 180.0;
            lat2 = lat2 * Math.PI / 180.0;
            double a = lat1 - lat2;
            double b = (long1 - long2) * Math.PI / 180.0;
            double d;
            double sa2, sb2;
            sa2 = Math.sin(a / 2.0);
            sb2 = Math.sin(b / 2.0);
            d =
                    2
                            * R
                            * Math.asin(Math.sqrt(sa2 * sa2 + Math.cos(lat1) * Math.cos(lat2) * sb2
                                    * sb2));
            return Double.valueOf(Math.round(d));
        }
        return null;
    }

    /**
     * 将json格式的字符串解析成Map对象 <li>
     * json格式：{"name":"admin","retries":"3fff","testname" :"ddd","testretries":"fffffffff"}
     */
    @SuppressWarnings("rawtypes")
    public static HashMap<String, Object> toHashMap(JSONObject jsonObject) {
        HashMap<String, Object> data = new HashMap<String, Object>();
        Iterator it = jsonObject.keys();
        // 遍历jsonObject数据，添加到Map对象
        while (it.hasNext()) {
            String key = String.valueOf(it.next());
            String value = (String) jsonObject.get(key);
            data.put(key, value);
        }
        return data;
    }

    /**
     * 
     * 根据距离排序
     * 
     * @author hexin-pc
     * @date 2016年1月14日 下午6:15:55
     * @param list
     * @return
     */
    public static List<Map<String, Object>> sort(List<Map<String, Object>> list) {
        if (list != null && list.size() > 1) {
            for (int i = 0; i < list.size() - 1; i++) {
                for (int j = 0; j < list.size() - i - 1; j++) {
                    // 把大的值交换到后面
                    if ((Double) list.get(j).get("distance") > (Double) list.get(j + 1).get(
                            "distance")) {
                        Object temp = list.get(j).get("distance");
                        list.get(j).put("distance", list.get(j + 1).get("distance"));
                        list.get(j + 1).put("distance", temp);
                    }
                }
            }
        }
        return list;
    }

    /**
     * 
     * 根据经纬度 计算距离添加
     * 
     * @author hexin-pc
     * @date 2016年1月14日 下午6:15:18
     * @param list
     * @param long1
     * @param lat1
     * @return
     */
    public static List<Map<String, Object>> calculateDistance(List<Map<String, Object>> list,
            double long1, double lat1) {
        for (Map<String, Object> map : list) {
            Double distance =
                    Distance(long1, lat1, Double.valueOf(map.get("glon").toString()),
                            Double.valueOf(map.get("glat").toString()));
            map.put("distance", distance);
        }
        return list;
    }

    public static String urldecode(String string) {
        if (!isEmpty(string)) {
            try {
                string = URLDecoder.decode(string, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                string = null;
                e.printStackTrace();
            }
        }
        return string;
    }

    /**
     * 图片尺寸处理
     * 
     * @param size 1最小 4最大
     * @param imagePath 图片原路径
     * @return
     */
    public static String ImageSizeProcessing(int size, String imagePath) {
        if (!isEmpty(imagePath)) {
            String sizeString = "";
            switch (size) {
                case 1:
                    sizeString = "_s";
                    break;
                case 2:
                    sizeString = "_m";
                    break;
                case 3:
                    sizeString = "_b";
                    break;
                case 4:
                    sizeString = "_l";
                    break;
                default:
                    break;
            }
            String str =
                    imagePath.subSequence(0, imagePath.lastIndexOf(".")) + sizeString
                            + imagePath.subSequence(imagePath.lastIndexOf("."), imagePath.length());
            return str;
        }
        return null;
    }

    /***
     * 过滤特殊字符
     * 
     * @param str
     * @return
     * @throws PatternSyntaxException
     */
    public static String StringFilter(String str) throws PatternSyntaxException {
        // 只允许字母和数字
        // String regEx = "[^a-zA-Z0-9]";
        // 清除掉所有特殊字符
        String regEx = "[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~！@#￥%……&*（）——+|{}【】‘；：”“’。，、？]";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(str);
        return m.replaceAll("").trim();
    }

    /**
     * string 转化为 date
     * 
     * @param createbegintime
     * @return
     */
    public static Date StringToDate(String stringtime) {
        Date datetime = null;
        if (!isEmpty(stringtime)) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            try {
                datetime = sdf.parse(stringtime);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        return datetime;
    }

    public static String getExceptionDetail(Exception ex) {
        String str = ex.toString();
        StackTraceElement[] stack = ex.getStackTrace();
        for (StackTraceElement ste : stack) {
            str += "\n" + ste.toString();
        }
        return str;
    }

    /**
     * 通过key 获取国际化信息
     * 
     * @param request
     * @param string
     * @return
     */
    public static String getMessagesByKey(HttpServletRequest request, String string) {
        RequestContext requestContext = new RequestContext(request);
        String ss = requestContext.getMessage(string);
        return ss;
    }

    /**
     * 替换 特殊字符
     * 
     * @param productname
     * @return
     */
    public static String replaceSpecialCharacters(String productname) {
        return productname.replaceAll("&", "");
    }

    /**
     * 输出错误信息
     * 
     * @author yangwenwei
     * @date 2016年6月6日下午3:00:34
     * @param e
     * @return
     *
     */
    public static String getErrorInfoFromException(Exception e) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        return sw.toString();
    }

    public static String DoubleToString(Double adjustamount) {
        if (adjustamount == null) {
            return null;
        }
        DecimalFormat df = new DecimalFormat("#.00");
        return df.format(adjustamount);
    }

    public static String listToString(List<String> stringList) {
        if (stringList == null) {
            return null;
        }
        StringBuilder result = new StringBuilder();
        boolean flag = false;
        for (String string : stringList) {
            if (flag) {
                result.append(",");
            } else {
                flag = true;
            }
            result.append(string);
        }
        return result.toString();
    }

    /**
     * 除去字符串开始和结束的","
     * 
     * @author yangwenwei
     * @date 2016年9月20日 下午12:36:43
     * @param targetStr
     * @return
     */
    public static String cutStartEndComma(String targetStr) {
        if (!isEmpty(targetStr)) {
            String result = targetStr;
            if (result.length() >= 1) {
                if (result.startsWith(",")) {
                    result = result.substring(1);
                }
                if (result.endsWith(",")) {
                    result = result.substring(0, result.length() - 1);
                }
                return result;
            } else {
                return null;
            }
        } else {
            return null;
        }
    }

    /**
     * 
     * @author yangwenwei
     * @date 2016年11月9日 下午7:35:58
     * @param obj
     * @param fieldName
     * @return
     */
    public static Object getValueByFieldName(Object obj, String fieldName) {
        try {
            Method m = obj.getClass().getMethod("get" + getMethodName(fieldName));
            return m.invoke(obj);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 
     * @author yangwenwei
     * @date 2016年11月9日 下午7:36:03
     * @param fildeName
     * @return
     * @throws Exception
     */
    private static String getMethodName(String fildeName) throws Exception {
        byte[] items = fildeName.getBytes();
        items[0] = (byte) ((char) items[0] - 'a' + 'A');
        return new String(items);
    }
}
